<html><head>
<link href="utility.css" rel="stylesheet" type="text/css"/>
<!-- script src="fetchers.js"></script -->
<script src="db.js"></script>
<script>
function treeToggle(ev, url) {
    var el = ev.target;
    var sub = document.getElementById("sub");
    if (sub) {
        var last = sub.previousElementSibling;
        sub.parentNode.removeChild(sub);
        last.className = "treenode closed";
        if (last==el) {
            return ;
        }
    }
    if (-1!=el.className.indexOf("opened")) {
        el.className = "treenode closed";
        return ;
    }

    el.className = "treenode opened";
    sub = document.createElement("div");
    sub.id = "sub";
    if (el.nextElementSibling) {
        el.parentNode.insertBefore(sub, el.nextElementSibling);
    } else {
        el.parentNode.appendChild(sub);
    }
    treeKidClicked(el, url);
    // now, fill sub with kids...
    SeoprofesionalDb.get_sub(url, function(kid) {
        var el = document.createElement("div");
        var text = kid;
        if (0 && kid!=url) {
            text = "..." + text.substring(url.length);
        }
        el.innerText = text;
        el.addEventListener("click", function() {treeKidClicked(event, kid);}, false);
        sub.appendChild(el);
    });
}
function treeKidClicked(el, url) {
    document.getElementById("plot").src = "popup.html?chartlinks=1&url=" + url;
    document.getElementById("plothead").href = url;
    document.getElementById("plothead").innerText = url;
    var el = document.getElementById("commands");
    var s = "";
}
function fill() {
  var tree = document.getElementById("tree");
  SeoprofesionalDb.get_whitelist(function(url) {
    var el;
    el = document.createElement("div");
    el.innerText = url;
    el.className = "treenode closed";
    el.addEventListener("click", function() {treeToggle(event, url);}, false);
    tree.appendChild(el);
  });
}

function init() {
  fill();
}
</script>
</head><body onload="init()">
<div id="head">
<a id="plothead"></a>
</div>
<div style="top: 40px; position: relative;">
  <div id="tree"></div>
  <div id="content">
    <iframe id="plot"></iframe>
    <ul id="commands"></ul>
  </div>
</div>
</body></html>

